<template>
    <div class="Institutional_information">
        <tmpHeader :index='0'/>
        <div class="main" v-show='info.title'>
            <!--机构名称 -->
            <div class="main_info">
                <span>机构名称：</span>
                <Input :value="info.title" style="width: 680px" disabled/>
            </div>
            <!--机构首图-->
            <div class="main_imgs">
                <span>机构首图：</span>
                <div class="demo-upload-list" v-for="(item,index) in uploadList" :key="index">
                    <div v-if="item.status === 'finished'">
                        <img :src="item.url">
                        <div class="demo-upload-list-cover">
                            <Icon type="ios-eye-outline" @click.native="handleView(item.name)"></Icon>
                            <Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
                        </div>
                    </div>
                    <div v-else>
                        <Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
                    </div>
                </div>
                <Upload
                    v-show="uploadList.length ==0"
                    ref="upload"
                    :show-upload-list="false"
                    :default-file-list="defaultList"
                    :on-success="handleSuccess"
                    :format="['jpg','jpeg','png']"
                    :max-size="1024"
                    :on-format-error="handleFormatError"
                    :on-exceeded-size="handleMaxSize"
                    :before-upload="handleBeforeUpload"
                    multiple
                    type="drag"
                    :action="uploadUrl"
                    :headers="fromData"
                    :data="uploadData"
                    style="display: inline-block;width:58px;"
                >
                    <div style="width: 58px;height:58px;line-height: 58px;">
                        <i class = "iconfont icon-shangchuan" style="font-size:18px;"></i>
                    </div>
                </Upload>
                <Modal title="预览图片" v-model="visible" footer-hide>
                    <img :src=" uploadList[0].url " v-if="visible" style="width: 100%">
                </Modal>
                <small style="color:#FF9966;margin-left:50px">备注：图片可上传jpg、jpeg、png格式，建议尺寸740*280且文件大小不超过1024KB</small>
            </div>
            <!--机构icon-->
            <div class="main_imgs">
                <span>机构Logo：</span>
                <div class="demo-upload-list" v-for="(items,index) in logolist" :key="index">
                    <div v-if="items.status === 'finished'">
                        <img :src="items.url">
                        <div class="demo-upload-list-cover">
                            <Icon type="ios-eye-outline" @click.native="handleViewicon(items.name)"></Icon>
                            <Icon type="ios-trash-outline" @click.native="handleRemoveicon(items)"></Icon>
                        </div>
                    </div>
                    <div v-else>
                        <Progress v-if="items.showProgress" :percent="items.percentage" hide-info></Progress>
                    </div>
                </div>
                <Upload
                    v-show="logolist.length ==0"
                    ref="logoupload"
                    :show-upload-list="false"
                    :default-file-list="defaultLists"
                    :on-success="handleSuccessicon"
                    :format="['jpg','jpeg','png']"
                    :max-size="1024"
                    :on-format-error="handleFormatErroricon"
                    :on-exceeded-size="handleMaxSizeicon"
                    :before-upload="handleBeforeUploadicon"
                    multiple
                    type="drag"
                    :action="uploadUrl"
                    :headers="fromData"
                    :data="uploadData"
                    style="display: inline-block;width:58px;"
                >
                    <div style="width: 58px;height:58px;line-height: 58px;">
                        <i class = "iconfont icon-shangchuan" style="font-size:18px;"></i>
                    </div>
                </Upload>
                <Modal title="预览图片" v-model="visibles" footer-hide>
                    <img :src=" logolist[0].url " v-if="visibles" style="width: 100%">
                </Modal>
                <small style="color:#FF9966;margin-left:50px">备注：图片可上传jpg、jpeg、png格式，建议尺寸150*150且文件大小不超过1024KB</small>
            </div>
            <!--是否开通互联网医院-->
            <div class="main_yy">
                <span class="main_yy_name">开通互联网医院：</span>
                <iSwitch size="large"  v-model="info.internetHospital" @on-change="change">
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
            </div>
            <!--医院关联公众号-->
            <div class="main_moban" style='flex-wrap:wrap;height:auto;'>
                <span>医院关联公众号：</span>
                <div style='position:relative;width:500px;height:auto;'>
                    <div v-for='(item,index) in info.wxAppList' :key='index' style='margin:10px 0;'>
                        <Select v-model="item.value" style="width:150px;margin-right:4px;" :disabled="status" @on-change='relationwx' clearable @on-clear='relationwx'>
                            <Option
                                v-for ="item in gzh"
                                :value="item.appid"
                                :key="item.appid"
                                :disabled='item.status'
                                style='text-align:center;'
                            >{{ item.nick }}</Option>
                        </Select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <span style="min-width:0px;margin-right:20px">医院主公众号:</span>
                        <iSwitch size="large"  v-model='item.imaster' style='min-width:auto;' @on-change='masterSwitch(index)' :disabled='!item.value'  >
                            <span slot="open">开通</span>
                            <span slot="close">关闭</span>
                        </iSwitch>
                    </div>
                    <div style='position:absolute;top:15px;right:0;'>
                        <button class="cus-btn" @click='addAppid'>+</button>
                        <button class="cus-btn" @click='unAppid'>-</button>
                    </div>
                </div>
            </div>
            <!--是否加入医院联盟-->
            <!-- <div class="main_yy">
                <span class="main_yy_name">加入医院联盟：</span>
                <iSwitch size="large"  v-model="info.unionHospital" :disabled="status" @on-change="change2">
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
                <small style="color:#FF9966;margin-left: 105px;margin-top:4px">备注：加入联盟后，可以在大平台引流患者。</small>
            </div> -->
            <!--医院联盟排序-->
            <div class="main_info">
                <span>医院机构排序：</span>
                <InputNumber :max="99999" :min="1" v-model="info.internetHospitalSort" placeholder="医院机构排序"
                style="width:150px;"
                ></InputNumber>
                <small style="color:#FF9966;margin-left: 10px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注:只能填写数字，1代表在主机构公众号下医院机构置顶以此类推</small>
            </div>
            <!-- 预约挂号排序 -->
            <!-- <div class="main_info">
                <span>预约挂号排序：</span>
                <InputNumber :max="99999" :min="1" v-model="info.appointmentRegistration" placeholder="预约挂号排序"
                style="width:150px;"></InputNumber>
                <small style="color:#FF9966;margin-left: 10px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注:只能填写数字，1代表置顶以此类推</small>
            </div> -->
            <!-- <p style='margin-left:8px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注:只能填写数字，1代表置顶以此类推</p> -->
            <!--是否开通处方流转-->
            <div class="main_yy">
                <span class="main_yy_name">开通处方流转：</span>
                <iSwitch size="large"  v-model="info.ipres" >
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
                <small style="color:#FF9966;margin-left: 110px;margin-top:4px">备注：开通后，可将在线开具的处方共享到处方流转平台。</small>
            </div>
            <!--处方流转平台接口ID-->
            <!-- <div class="main_info">
                <span>处方流转平台接口ID：</span>
                <Input v-model="info.prescriptionId" placeholder="请输入Id" style="width: 680px"/>
            </div> -->
            <!-- 预约挂号支付 -->
            <!-- <div class="main_yy">
                <span class="main_yy_name">预约挂号支付：</span>
                <iSwitch size="large"  v-model="info.registerPayStatus" >
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
                <small style="color:#FF9966;margin-left:110px;margin-top:4px">备注：开通后，在预约时直接支付挂号费。</small>
            </div>  -->
            <!-- 预约挂号池是否为第三方 -->
            <!-- <div  class="main_yy">
                <span class="main_yy_name">预约挂号池是否为第三方：</span>
                <iSwitch size="large"  v-model="info.registerIthirdparty" >
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
            </div>
            <div  class="main_yy">
                <span class="main_yy_name">是否支持平台配送：</span>
                <iSwitch size="large"  v-model="info.openDistribution" >
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
            </div> -->
            <!--是否加入远程门诊-->
            <div  class="main_yy">
                <span class="main_yy_name">是否开启远程门诊</span>
                <iSwitch size="large"  v-model="info.iremote" >
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
            </div>
            <!--是否加入远程会诊-->
            <div  class="main_yy">
                <span class="main_yy_name">是否开启远程会诊</span>
                <iSwitch size="large"  v-model="info.iremoteConsult" >
                    <span slot="open">开通</span>
                    <span slot="close">关闭</span>
                </iSwitch>
            </div>
            <div class="main_yy">
                <span class="main_yy_name">机构就诊卡模式：</span>
                <RadioGroup v-model="info.jzkgl">
                    <Radio :value="1" :label="1">实体就诊卡</Radio>
                    <Radio :value="2" :label="2">电子就诊卡</Radio>
                </RadioGroup>
                <small style="color:#FF9966;margin-left: 110px;margin-top:4px">备注：无论哪种模式，均需要在公众号配置显示开启，方可有效。</small>
            </div>
            <!--机构电子章-->
            <div class="main_imgs">
                <span>机构电子章：</span>
                <div class="demo-upload-list" v-for="(items,index) in chapterlist" :key="index">
                    <div v-if="items.status === 'finished'">
                        <img :src="items.url">
                        <div class="demo-upload-list-cover">
                            <Icon type="ios-eye-outline" @click.native="handleViewChapter(items.name)"></Icon>
                            <Icon type="ios-trash-outline" @click.native="handleRemoveChapter(items)"></Icon>
                        </div>
                    </div>
                    <div v-else>
                        <Progress v-if="items.showProgress" :percent="items.percentage" hide-info></Progress>
                    </div>
                </div>
                <Upload
                    v-show="chapterlist.length ==0"
                    ref="chapterupload"
                    :show-upload-list="false"
                    :default-file-list="defaultchapterList"
                    :on-success="handleSuccessChapter"
                    :format="['jpg','jpeg','png']"
                    :max-size="1024"
                    :on-format-error="handleFormatErrorChapter"
                    :on-exceeded-size="handleMaxSizeChapter"
                    :before-upload="handleBeforeUploadChapter"
                    multiple
                    type="drag"
                    :action="uploadUrl"
                    :headers="fromData"
                    :data="chapteruploadData"
                    style="display: inline-block;width:58px;"
                >
                    <div style="width: 58px;height:58px;line-height: 58px;">
                        <i class = "iconfont icon-shangchuan" style="font-size:18px;"></i>
                    </div>
                </Upload>
                <Modal title="预览图片" v-model="chaptervisible" footer-hide>
                    <img :src=" chapterlist[0].url " v-if="chaptervisible" style="width: 100%">
                </Modal>
                <small style="color:#FF9966;margin-left:50px">备注：图片可上传jpg、jpeg、png格式，建议尺寸150*150且文件大小不超过1024KB</small>
            </div>
            <!-- 医保定点 -->
            <!-- <div class="main_yy">
                <span class="main_yy_name">省医保定点：</span>
                <RadioGroup class="right" v-model="info.provinceMedical">
                    <Radio label="1">是</Radio>
                    <Radio label="0">否</Radio>
                </RadioGroup>
            </div> -->
             <!-- <div v-else>{{['否', '是'][info.provinceMedical]}}</div> -->
            <!-- <div class="main_yy">
                <span class="main_yy_name">市医保定点：</span>
                <RadioGroup  class="right" v-model="info.cityMedical">
                    <Radio label="1">是</Radio>
                    <Radio label="0">否</Radio>
                </RadioGroup>
            </div> -->
            <!-- <div v-else>{{['否', '是'][info.cityMedical]}}</div> -->
            <!--保存-->
            <div class="main_save">
                <Button type="primary" :disabled='disabled' @click="save" class="btn">
                    <Icon type="ios-checkmark" style="margin-right: 5px" />保存
                </Button>
                <Button @click="$router.push('/index/organizat/contentmen/home')" class="btn">
                    <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
                </Button>
            </div>
        </div>
    </div>
</template>

<script>
import vueEditor from "@/components/vueEditor";
import tmpHeader from "@/pages/organizat/contentmen/tmpHeader";
import code from "@/configs/base.js";
import cookie from "@/utils/cookie.js";
import api from "@/api/commonApi";
export default {
    components: {
        tmpHeader,
        vueEditor,
        "imyswitch": {
            template: '<div class="main_yy">'+
                            '<span class="main_yy_name" style="margin-right:10px;min-width:150px;">{{ title }}</span>'+
                            '<iSwitch v-model="flag" @on-change="Change" size="large">'+
                                '<span slot="open">开启</span>'+
                                '<span slot="close">关闭</span>'+
                            '</iSwitch>'+
                    '</div>',
            props: ['status','title'],
            data () {
                return {
                    flag:false
                }
            },
            created () {
                this.flag = Boolean(this.status)
            },
            methods: {
                Change (status) {
                    this.$emit("statuschange",status)
                }
            }
        }
    },
    data() {
        return {
            info: {
                // 机构名称
                title:"",
                // 机构等级
                grade:"",
                // 医联体上级医院
                orgParentCode:"",
                // 背景模板
                cssTemplate:"",
                // 机构简介
                content: "",
                // 乘车路线
                route:"",
                // 机构电话
                telephone:"",
                // 机构地址
                hosAddr:"",
                // 互联网医院
                internetHospital:false,
                // 医院关联公众号
                wxAppList: [],
                // 医院聪明
                unionHospital:false,
                // 联盟排序
                internetHospitalSort:"",
                // 预约挂号排序
                appointmentRegistration:"",
                // 是否开通处方流转
                ipres: false,
                // 处方流转平台接口ID
                prescriptionId:"",
                // 远程门诊
                iremote: false,
                // 远程会诊
                iremoteConsult: false,
                // 强制用卷
                usedCoupon: false,
                // 预约挂号支付
                registerPayStatus: false,
                // 预约挂号池是否为第三方
                registerIthirdparty: false,
                //是否支持平台配送
                openDistribution: false,
                //省医保定点
                provinceMedical: false,
                //市医保定点
                cityMedical:false,
                // 关联主公众 号
                imaster: "",
                jzkgl: '',
            },
            // 所有的公众号列表
            gzh: [],
            // 当前医院已经关联的公众号列表
            selectGzh:[],
            // 上传图片相关
            uploadList: [],
            logolist:[],

            visible: false,
            visibles: false,
            chaptervisible: false,
            defaultList: [],
            defaultLists: [],
            imgName: "",
            uploadModal: true,
            uploadData: {
                json: '{"urlCode":"' + code.urlCode.hospitalBanner + '"}'
            },
            // uploadDatas: {
            //     json: '{"urlCode":"' + code.urlCode.hospitalBanner + '"}'
            // },
            activeUploadId: "5c2bf345-b973-4ffd-a52e-87bb9c1d2b72",
            uploadUrl: api.fileAll,
            images: "",
            logoimg:"",
            id: sessionStorage.getItem("hospitalId"),
            status: false,
            hospitalFlag: false,
            urlCode: '{"urlCode":"' + code.urlCode.richText + '"}',
            disabled: false,
            //电子章字段
            chapter:'',
            chapterlist:[],
            chapterImg: '',
            defaultchapterList: [],
            chapteruploadData: {
                json: '{"urlCode":"' + code.urlCode.chapterCode + '"}'
            },
        };
    },
    created() {
        localStorage.setItem("homeIndex", 0);
        // 获取医院等级,医联体,公众号数据
        this.addData();
    },
    mounted() {
        this.uploadList = this.$refs.upload.fileList;
        this.logolist = this.$refs.logoupload.fileList;
        this.chapterlist = this.$refs.chapterupload.fileList;
        // 医院信息
        this.$axios
            .post(api.mechanismregSearch, {
                id: this.id
            })
            .then(res => {
                if (res.data.success) {
                    let ret = res.data.object;
                    console.log('机构详细信息',ret);
                    // 医院图片
                    if (ret.hosIcon) {
                        this.source = ret.hosIcon;
                        this.uploadList.push({
                            name: "a42bdcc1178e62b4694c830f028db5c0",
                            percentage: 100,
                            status: "finished",
                            uid: 1544263544970,
                            url:
                                this.fileBaseUrl +
                                this.pictureFormat(ret.hosIcon)
                        });
                    }
                    if (ret.hosLogo) {
                        this.sources = ret.hosLogo;
                        this.logolist.push({
                            name: "a42bdcc1178e62b4694c830f028db5c0",
                            percentage: 100,
                            status: "finished",
                            uid: 1544263544970,
                            url:
                                this.fileBaseUrl +
                                this.pictureFormat(ret.hosLogo)
                        });
                    }
                    if (ret.signature) {
                        this.chapter = ret.signature;
                        this.chapterlist.push({
                            name: "a42bdcc1178e62b4694c830f028db5c0",
                            percentage: 100,
                            status: "finished",
                            uid: 1544263544970,
                            url:
                                this.fileBaseUrl +
                                this.pictureFormat(ret.signature)
                        });
                    }
                    // 医院名字
                    this.info.title = ret.orgName
                    // 机构等级
                    this.info.grade = ret.grade
                    // 医联体上级医院
                    this.info.orgParentCode = ret.orgParentCode
                    // 背景模板
                    // this.info.cssTemplate = ret.cssTemplate
                    // 简介
                    this.info.content = ret.hosIntroduction;
                    //路线
                    this.info.route = ret.route
                    //电话
                    // this.info.telephone = ret.telephone
                    this.info.internetHospitalSort = ret.internetHospitalSort
                    // 地址
                    this.info.hosAddr = ret.hosAddr
                    // appidList关联公众号列表
                    let wxAppList = ret.appidList || []
                    //互联网医院
                    this.info.internetHospital = Boolean(ret.internetHospital)
                    if (Boolean(ret.internetHospital)) {
                        this.status = false;
                        localStorage.setItem("status", "show");
                         // 医院关联公众号回显
                        // if (Boolean(wxAppList.length)) {
                        //     wxAppList.forEach(i => {
                        //         this.info.wxAppList.push({
                        //             value : i.appid,
                        //             status : true,
                        //             imaster: Boolean(i.imaster)
                        //         })
                        //     })
                        // } else {
                        //     this.info.wxAppList.push({
                        //         value : '',
                        //         status : false,
                        //         imaster: false
                        //     })
                        // }
                    } else {
                        this.status = true;
                        localStorage.setItem("status", "");
                        // this.info.wxAppList.push({
                        //     value : '',
                        //     status : false,
                        //     imaster: false
                        // })
                    }
                     // 医院关联公众号回显
                    if (Boolean(wxAppList.length)) {
                        wxAppList.forEach(i => {
                            this.info.wxAppList.push({
                                value : i.appid,
                                status : true,
                                imaster: Boolean(i.imaster)
                            })
                        })
                    } else {
                        this.info.wxAppList.push({
                            value : '',
                            status : false,
                            imaster: false
                        })
                    }
                    // 医院联盟
                    this.info.unionHospital = Boolean(ret.unionHospital);
                    if (Boolean(ret.unionHospital)) {
                        this.hospitalFlag = false;
                    } else {
                        this.hospitalFlag = true;
                    }
                    // 处方流转
                    this.info.ipres = Boolean(ret.ipres);
                    // 流转平台id
                    this.info.prescriptionId = ret.prescriptionId
                    // 开启远程门诊
                    this.info.iremote = Boolean(ret.iremote);
                    if (Boolean(ret.iremote)) {
                        localStorage.setItem("doctor", "show");
                    } else {
                        localStorage.setItem("doctor", "");
                    }
                  // 开启远程会诊
                  this.info.iremoteConsult = Boolean(ret.iremoteConsult);
                  if (Boolean(ret.iremoteConsult)) {
                    localStorage.setItem("iremoteConsult", "show");
                  } else {
                    localStorage.setItem("iremoteConsult", "");
                  }
                    // 预约挂号排序
                    let appointmentRegistration = ret.appointmentRegistration;
                    if(!Number(appointmentRegistration)) {
                        appointmentRegistration = ''
                    }
                    this.appointmentRegistration = appointmentRegistration
                    this.info.appointmentRegistration = appointmentRegistration;
                    // 是否强制用卷
                    this.info.usedCoupon = Boolean(ret.usedCoupon);
                    // 预约挂号支付
                    this.info.registerPayStatus = Boolean(ret.registerPayStatus);
                    // 预约挂号池是否为第三方
                    this.info.registerIthirdparty = Boolean(ret.registerIthirdparty);
                    this.info.openDistribution = Boolean(ret.openDistribution);
                    //省医保定点
                    this.info.provinceMedical = ret.provinceMedical;
                    this.info.jzkgl = ret.jzkgl;
                    //市医保定点
                    this.info.cityMedical = ret.cityMedical;
                }
            });
    },
    methods: {
        // 机构简介
        afterChange(val) {
            this.info.content = val;
        },
        // 强制用卷
        usedCouponChange (status) {
            this.info.usedCoupon = status
        },
        // 预约挂号支付
        registerPayStatusChange (status) {
            this.info.registerPayStatus = status
        },
        // 是否加入远程门诊
        switch4Change (status) {
          this.info.iremote = status
        },
        // 是否加入远程会诊
      switch3Change(status) {
        this.info.iremoteConsult = status
      },
        // 预约挂号池是否为第三方
        registerIthirdpartyChange (status) {
            this.info.registerIthirdparty = status
        },
        // 医院主公众号
        masterSwitch(index) {
            console.log(index)
            console.log(this.info.wxAppList)
            let status = this.info.wxAppList[index].imaster;
            console.log(status)
            if(status) {
                this.info.wxAppList.forEach((item, s) => {
                    console.log(s)
                    if(s == index) {
                        item.imaster = status
                    } else {
                        item.imaster = false
                    }
                })
            }
        },
        // 公众号列表限制
        addAppid () {
            if (this.status) {
                this.$Message.error("请开通互联网医院")
                return ""
            }
            // 所有公众号列表
            let gzhlen = this.gzh.length;
            // 添加的公众号列表
            let applen = this.info.wxAppList.length
            if (gzhlen <= applen) {
                this.$Message.error('当前仅有'+gzhlen+'个公众号可关联')
                return ""
            }
            this.info.wxAppList.forEach(item => {
                this.gzh.forEach(i => {
                    if(i.appid == item.value) {
                        i.status = true;
                    }
                })
            })
            this.info.wxAppList.push({
                value : "",
                status : false,
                ipay: false,
                imaster: false
            })
            this.relationwx();
        },
        unAppid () {
            if (this.status) {
                this.$Message.error("请开通互联网医院")
                return ""
            }
            if(this.info.wxAppList.length != 1) {
                // this.info.wxAppList.splice(this.info.wxAppList.length-1, 1);
                this.info.wxAppList.pop();
            } else {
                this.$Message.error("请至少关联一个公众号")
            }
             this.relationwx();
        },
        // 已关联公众号列表
        relationwx () {
            let list = []
            // 初始化
            this.gzh.forEach((i,m) => {
                i.status = false
            })
            this.info.wxAppList.forEach(item => {
                item.imaster = false
            })
            // 新选择的公众号
            this.info.wxAppList.forEach(item => {
                this.gzh.forEach((i,m) => {
                    if (item.value == i.appid) {
                        list.push(i)
                        i.status = true
                    }
                })
            })
            this.selectGzh = list
        },
        // 是否开通互联网医院关联数据
        change(status) {
            if (status) {
                this.status = false;

            } else {
                this.info.wxAppList.forEach(item => {
                    item.value = ''
                })
                this.status = true;
                this.info.wxappPay = null;
                this.info.unionHospital = false;
                this.hospitalFlag = true;
            }
        },
        // 是否加入医院联盟控制医院排序
        change2(status) {
            if (status) {
                this.hospitalFlag = false;
            } else {
                this.hospitalFlag = true;
            }
        },
        // 医院修改完成
        save() {
            this.disabled = true
            //机构首图
            let images = "";
            let logoimg = "";
            let chapterImg = "";
            if (this.images != "" && this.uploadList.length) {
                images = this.images;
            } else if (this.uploadList.length) {
                images = this.source;
            } else {
                images = "";
            }
            //icon
            if (this.logoimg != "" && this.logolist.length) {
                logoimg = this.logoimg;
            } else if (this.logolist.length) {
                logoimg = this.sources;
            } else {
                logoimg = "";
            }
            //电子章
            if (this.chapterImg != "" && this.chapterlist.length) {
                chapterImg = this.chapterImg;
            } else if (this.chapterlist.length) {
                chapterImg = this.chapter;
            } else {
                chapterImg = "";
            }
              //关联的多个公众号的appid
            let appid = []
            let appidFlag = true;
            if(this.info.internetHospital) {
                this.info.wxAppList.forEach(item => {
                    if(Boolean(item.value)) {
                        appid.push({
                            appid: item.value,
                            imaster: Number(item.imaster)
                        })
                    }
                })
                appid.forEach(s => {
                    if(Boolean(s.imaster)) {
                        appidFlag = false;
                    }
                })
                if(appidFlag || !appid.length) {
                    this.$Message.error("开通互联网医院时,请确认是否关联公众号或主公众号");
                    this.disabled = false
                    return ''
                }
            }
            // 全部参数
            let params = {
                id: this.id,
                //上级编码
                orgParentCode: this.info.orgParentCode,
                // 医院图标
                hosIcon: images,
                //医院icon
                // hosLogo: logoimages,
                hosLogo: logoimg,
                signature: chapterImg,
                //机构等级
                grade: this.info.grade,
                //模板
                // cssTemplate: this.info.cssTemplate,
                //路线
                route: this.info.route,
                //电话
                // telephone: this.info.telephone,
                //简介
                hosIntroduction: this.info.content,
                //地址
                hosAddr: this.info.hosAddr,
                //互联网医院
                internetHospital: Number(this.info.internetHospital),
                // 关联公众号列表
                wxAppList: appid,
                //医院联盟
                unionHospital: Number(this.info.unionHospital),
                //处方平台UID
                prescriptionId: this.info.prescriptionId,
                // 医院排序
                internetHospitalSort: this.info.internetHospitalSort,
                // 预约挂号排序
                // appointmentRegistration:this.info.appointmentRegistration,

                //处方流转
                ipres: Number(this.info.ipres),
                // 开启远程门诊
                iremote: Number(this.info.iremote),
                // 开启远程会诊
                iremoteConsult: Number(this.info.iremoteConsult),
                // 是否强制用卷
                usedCoupon: Number(this.info.usedCoupon),
                // 预约挂号支付
                registerPayStatus: Number(this.info.registerPayStatus),
                // 预约挂号池是否为第三方
                registerIthirdparty: Number(this.info.registerIthirdparty),
                openDistribution: Number(this.info.openDistribution),
                //省医保定点
                provinceMedical: Number(this.info.provinceMedical),
                //市医保定点
                cityMedical: Number(this.info.cityMedical),
                // 医生关联公众号
                wxAppList : appid,
                jzkgl : this.info.jzkgl,
            };
            if(this.title == '') {
                this.$Message.error("医院数据加载失败，请重试")
                this.disabled = false
                return ""
            }
            // 当医院关闭互联网医院时把appid清空
            if (!this.info.internetHospital) {
                params.wxAppList = []
            } else if(this.info.internetHospital) {
                if(params.wxAppList.length == 0) {
                    this.$Message.error("请选择医院关联公众号")
                    this.disabled = false
                    return ""
                }
            }
            // 远程门诊状态缓存
            if (this.info.iremote) {
                localStorage.setItem("doctor", "show");
            } else {
                localStorage.setItem("doctor", "");
            }
            // 远程会诊状态缓存
            if (this.info.iremoteConsult) {
              localStorage.setItem("iremoteConsult", "show");
            } else {
              localStorage.setItem("iremoteConsult", "");
            }
            this.$axios
                .post(api.saveHospital, params)
                .then(res => {
                    if (res.data.success) {
                        this.$Message.info(res.data.message);
                        setTimeout(() => {
                            this.disabled = false
                        }, 1000);
                        this.$router.push({
                            path: '/index/organizat/contentmen/home',
                            // query: {    }
                        })
                    } else {
                        let message = ''
                        if(Boolean(res.data.message)) {
                            message = res.data.message
                            this.disabled = false
                        }
                        this.$Message.error(message);
                    }
                })

            // 开通互联网医院状态缓存/动态新闻/预约科室/院内科室
            if (this.info.internetHospital) {
                localStorage.setItem("status", "show");
            } else {
                localStorage.setItem("status", "");
            }
        },
        // 上传图片相关事件
        handleView(name) {
            this.imgName = name;
            this.visible = true;
        },
        handleRemove(file) {
            const fileList = this.$refs.upload.fileList;
            this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
        },
        handleSuccess(res, file) {
            res = this.uploadFileDecrypt(res);
            file.url = this.fileBaseUrl + res.object[0].fileName;
            this.images = JSON.stringify(res.object[0]);
            file.name = res.object[0].fileName;
        },
        handleFormatError(file) {
            this.$Notice.warning({
                title: "The file format is incorrect",
                desc:
                    "File format of " +
                    file.name +
                    " is incorrect, please select jpg or png."
            });
        },
        handleMaxSize(file) {
            this.$Notice.warning({
                title: "文件过大",
                desc: `文件${file.name}过大，文件最大限制为1024KB`
            });
        },
        handleBeforeUpload() {
            const check = this.uploadList.length < 1;
            if (!check) {
                this.$Message.info("只能上传一张图片");
            }
            return check;
        },
        // icon上传图片相关事件
        handleViewicon(name) {
            this.imgName = name;
            this.visibles = true;
        },
        handleRemoveicon(file) {
            const fileLists = this.$refs.logoupload.fileList;
            this.$refs.logoupload.fileList.splice(fileLists.indexOf(file), 1);
        },
        handleSuccessicon(res, file) {
            res = this.uploadFileDecrypt(res);
            file.url = this.fileBaseUrl + res.object[0].fileName;
            // this.images = JSON.stringify(res.object[0]);
            this.logoimg = JSON.stringify(res.object[0]);
            file.name = res.object[0].fileName;
        },
        handleFormatErroricon(file) {
            this.$Notice.warning({
                title: "The file format is incorrect",
                desc:
                    "File format of " +
                    file.name +
                    " is incorrect, please select jpg or png."
            });
        },
        handleMaxSizeicon(file) {
            this.$Notice.warning({
                title: "文件过大",
                desc: `文件${file.name}过大，文件最大限制为1024KB`
            });
        },
        handleBeforeUploadicon() {
            const check = this.logolist.length < 1;
            if (!check) {
                this.$Message.info("只能上传一张图片");
            }
            return check;
        },
        // 	电子签章上传图片相关事件
        handleViewChapter(name) {
            this.imgName = name;
            this.chaptervisible = true;
        },
        handleRemoveChapter(file) {
            const chapterfileList = this.$refs.chapterupload.fileList;
            this.$refs.chapterupload.fileList.splice(chapterfileList.indexOf(file), 1);
        },
        handleSuccessChapter(res, file) {
            res = this.uploadFileDecrypt(res);
            file.url = this.fileBaseUrl + res.object[0].fileName;
            // this.images = JSON.stringify(res.object[0]);
            this.chapterImg = JSON.stringify(res.object[0]);
            file.name = res.object[0].fileName;
        },
        handleFormatErrorChapter(file) {
            this.$Notice.warning({
                title: "The file format is incorrect",
                desc:
                    "File format of " +
                    file.name +
                    " is incorrect, please select jpg or png."
            });
        },
        handleMaxSizeChapter(file) {
            this.$Notice.warning({
                title: "文件过大",
                desc: `文件${file.name}过大，文件最大限制为1024KB`
            });
        },
        handleBeforeUploadChapter() {
            const check = this.chapterlist.length < 1;
            if (!check) {
                this.$Message.info("只能上传一张图片");
            }
            return check;
        },
        // 加载医院等级,医联体,公众号数据
        addData() {
            // 公众号
            this.$axios.post(api.WxApp, {}).then(res => {
                if (res.data.success) {
                    let ret = res.data.object;
                    ret.forEach(item => {
                        item.status = false
                        item.ipay = false
                    })
                    this.gzh = ret;
                }
            });
            // 医院关联公众号
            this.$axios.post(api.attentWxApp, {
                hospitalId:this.id
            }).then(res => {
                if(res.data.success) {
                    let ret = res.data.object;
                    this.selectGzh = ret.filter(item =>{
                        return item.appid != 'wxe2a09bde0ab0a2d2'
                    })
                    console.log('医院关联公众号', ret);
                }
            })
        }
    },
};
</script>

<style scoped lang="less">
.demo-upload-list {
    display: inline-block;
    width: 60px;
    height: 60px;
    text-align: center;
    line-height: 60px;
    border: 1px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    margin-right: 4px;
}
.demo-upload-list img {
    width: 100%;
    height: 100%;
}
.demo-upload-list-cover {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list:hover .demo-upload-list-cover {
    display: block;
}
.demo-upload-list-cover i {
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    margin: 0 2px;
}
.main_enable {
    display: flex;
    flex-direction: row;
    width: 80%;
    height: 30px;
    margin: 5px auto;
    align-items: center;
}
.Institutional_information {
    width: 100%;
    padding: 10px 30px;
    margin: 0 auto;
    background: #fff;
    .main {
        width: 80%;
        padding: 30px 0;
        margin: 0 auto;
        .main_info {
            display: flex;
            flex-direction: row;
            width: 80%;
            height: 30px;
            margin: 5px auto;
            margin-bottom: 20px;
            align-items: center;
            span {
                display: inline-block;
                min-width: 150px;
                line-height: 30px;
            }
            input {
                line-height: 30px;
                display: inline-block;
                width: calc(100% - 200px);
                outline: none;
                text-indent: 5px;
            }
        }
        .main_yy {
            display: flex;
            flex-direction: row;
            width: 80%;
            height: 30px;
            margin: 5px auto;
            margin-bottom: 20px;
            .main_yy_name {
                display: inline-block;
                min-width: 150px;
                margin-right: 10px;
            }
        }
        .main_imgs,
        .main_type,
        .main_moban {
            display: flex;
            flex-direction: row;
            width: 80%;
            // height: 30px;
            margin: 5px auto;
            margin-bottom: 20px;
            align-items:center;
            span {
                display: inline-block;
                min-width: 150px;
            }
            .cus-btn{
                width:30px;
                height:30px;
                line-height: 30px;
                color: #ffffff;
                font-size: 30px;
                border: 0;
                border-radius: 50%;
                background: #5362e1;
                border:none;
                outline:none;
                margin-left:10px;
            }
        }
        .main_imgs {
            height: auto;
        }
        .main_jianjie {
            display: flex;
            flex-direction: row;
            width: 80%;
            height: auto;
            margin: 5px auto;
            span {
                display: inline-block;
                min-width: 150px;
            }
            div {
                margin: 0;
            }
        }
        .main_save {
            width: 60%;
            margin: 20px auto;
            text-align: center;
            // margin-left: 500px;
            // display: flex;
            // flex-direction: row;
            // justify-content: space-around;
            .btn {
                width: 75px;
                height: 35px;
            }
        }
    }
}
</style>
